The present invention relates generally to a class of semiconductor microprocessors utilized as microcontrollers to perform selective control functions on an external controlled system.
Microcontrollers having all peripherals embedded on the same single microcontroller chip have become increasingly popular in a large number of diverse control applications. These include, for example, pocket pagers, meters and testers, keyboard controllers capable of offloading many tasks which would otherwise require handling by the processor in personal computers, modems for command interpretation and data transmission, printer buffers for high speed data dumping, color plotters, color copiers, electronic typewriters, cable TV terminal equipment, lawn sprinkling controllers, credit card phone equipment, automotive applications including engine control modules, antilock braking systems, user-adjustable suspension control, and various other applications in industrial controls, telecommunications, automotive, appliance, computer and consumer markets.
Real time microcontrollers provide rapid solutions to signal processing algorithms and other numerically intensive computations, control events such as opening and closing of relays, position and speed of a motor, and other control functions. The central processing unit (CPU) of the microcontroller operates in conjunction with certain peripherals to perform the control function, including timers, signal ports, baud rate generators, and others.
Microcontrollers generally have one or more timers (typically registers which are, say, 8 or 16 bit wide) on board (i.e., integrated within the circuitry of the single chip itself). These timers are generally utilized to implement various timing functions. One such timing function may be a capture function, which enables recording a time stamp of the occurrence of an event of interest. For example, the event of interest may be a change in the logic state at an external pin, from "0" to "1", or "1" to "0". To capture the precise moment at which the pin change occurs, a 16 bit wide timer might be used together with a 16 bit wide shadow register that acts as a capture register. When the pin bit value changes, the timer value (count) is captured on the shadow register. Upon completion of the transfer, an interrupt is generated to the CPU of the microcontroller. Then, after the CPU has completed the task it was performing when the change took place, it can check on the timing of the event of interest at its leisure.
Thus, the availability of the capture register eliminates a need for the CPU to constantly monitor the pin for changes in state. Instead, the CPU is relieved, or "freed up" to perform its other tasks efficiently without wasted time, and, when time permits or when necessary, to make an inquiry to the shadow register to determine when the change in the logic state of the pin actually took place.
One practical example of the utility of the capture function is in the case of a pulse input to a pin. Capture can be set to occur on the rising edge of the pulse, and then on the failing edge. The two values can later be read, and subtracted from one another to calculate the width of the pulse in increments of time--a simple technique to measure pulse width. For this and similar purposes, the capture function enjoys widespread use in microcontrollers.
Another timing function commonly used in microcontrollers is a compare function, which is the opposite of the capture function. It may be desired to generate an event of some type, such as a pulse, or a change in logic state of a pin. Here again, a time base is provided by the timer (e.g., 16 bit wide), but in this case the associated shadow register is used to write the value or time stamp for the desired time of occurrence of the event. In this mode of operation, the shadow register is referred to as a "compare register".
Assume, for example, that the timer is in the midst of a count that commenced at zero and is heading toward 65,535 (i.e., a 16 bit value), and the logic state of the pin is to be set to change when the timer count reaches 10,000. In that case, the compare register is written to 10,000, and when the timer count matches that value, a `match` signal is generated by the compare register to toggle the pin and thereby initiate the logic state change. Another value may be written to the compare register indicative of the timing of another event, such as a timer count of 20,000 to evoke a `match` signal for resetting the pin to its previous logic state. The effect is that a pulse of predetermined width is generated at the pin with precise timing, by use of the compare function.
Thus, the compare function of the microcontroller device allows the user to set an event to occur at a precise specified time or times. Changing the logic state of a pin is, of course, only one of many examples: that could be cited. Other examples of events provided by this function include initiating a serial transmission, initiating an analog to digital conversion, or generating a software interrupt, to name a few. The choice of the desired event is, quite simply, a matter for the discretion of the microcontroller device user, whose interest is typically to achieve some objective in the external system controlled by the device.
Yet another timing function commonly employed in microcontrollers is Pulse Width Modulation (PWM). The PWM function involves repetitive events, in contrast to the single occurrence event `capture` and `compare` functions. If a capture is set--for example, it may be for the rising edge of a pulse--the value is read upon occurrence of that event, and then capture may be set for the next desired event. The compare function is handled in much the same way. A compare value may be set to toggle a pin, for example, and once that event is completed, another event may be scheduled.
With PWM, a repetitive waveform may be generated at a pin, with a period in which the pin is at one logic state (e.g., high) for a specified time interval, and at another logic state (e.g., low) for another specified time interval. The timing of the high and low states is selected to modulate the width of the pulse. The period of the PWM is the sum of the high and low intervals, and is determined by the timer.
PWM is especially useful to generate analog signals. For an 8 bit entity, for example, the pulse width may be set at any value between 0 and 255. A large number is thereby encoded into a digital signal, which is then used to generate an analog signal for performing the desired function, such as to drive a motor. The motor can be run at a slow rate by making the pulse width commensurately small, and at a faster rate by concomitantly increasing the pulse width.
In conventional microcontroller designs, timing functions of capture, compare and PWM are implemented and utilized separately from one another. One register is assigned to perform a compare function, another register allocated to a capture function, and still another to a PWM function, if the microcontroller includes one each of capture, compare and PWM functions. Certain microcontroller applications, however, require more than one of the same timing function. For instance, a three-phase motor control application typically requires three PWM outputs, while a four wheel anti-skid braking system application may require three or four capture inputs to measure wheel speeds. Yet another application may require a large number of compare functions.
Conventional microcontrollers, however, lack the capability to satisfy multiple timing function requirements of various different customer applications with a single device. A solution to this problem might be achieved by providing multiple capture, compare, and pulse width modulation functions on each chip. But such a solution would significantly increase the chip cost, and hence market price, with the result that the device would lose its attraction in the broader market, and tend to be restricted to only a relative few customer applications.
Accordingly, it is a principal object of the present invention to provide a single chip general purpose microcontroller or microprocessor device having multiple timing functions available and integrated into a single peripheral module to allow flexibility while minimizing die area and cost.
Another object is to provide such a device that allows each user to select the specific type and number of timing functions according to the needs of the particular user application for the device.